package com.codinghero.zqlb.spider.handler;

import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;

import com.codinghero.util.ListUtils;
import com.codinghero.zqlb.match.MatchUtils;
import com.codinghero.zqlb.match.SoccerMatch;

/**
 * 过滤转播频道
 * 
 * @author liutong01
 * 
 */
public class ChannelFilterHandler implements MatchHandler {

	public <T extends SoccerMatch> void handle(List<T> list) {
		Iterator<T> matchIter = list.iterator();
		
		while(matchIter.hasNext()) {
			SoccerMatch match = matchIter.next();

			if (match == null || ListUtils.isEmpty(match.getChannelNameList()))
				continue;
			Iterator<String> channelIter = match.getChannelNameList().iterator();
			while (channelIter.hasNext()) {
				String channel = channelIter.next();
				System.out.println(match.getStartDateStr() + "," + channel);
				Entry<String, Integer> e = MatchUtils.contains(
						SoccerMatch.CHANNEL_MAP, channel);
				if (e != null)
					match.getChannelIdSet().add(e.getValue());
			}
			match.setChannelIds(match.getChannelIdSet());
		}
	}

}
